import { useUserStore } from '@vben/stores';

import { requestClient } from '#/api/request';
/**
 *  获取1688商品分类
 * @param data parentId
 * @returns data list
 */
export async function get1688ShopCategory(data: any) {
  return requestClient.get<any>('shop/get1688ShopCategory', {
    params: data,
  });
}

/**
 * 获取用户授权的店铺信息
 *
 */
export async function getShopBindInfo() {
  return requestClient.get<any>('merchant/getMerchantInfo'); // { shopList: [] }; //
}

/**
 * 获取铺货设置
 */
export async function getSendGoodsInfo(data: any) {
  return requestClient.get<any>('merchant/getSendGoodsInfo', {
    params: data,
  });
}

/**
 * 新增修改店铺铺货设置
 */
export async function updateSendGoodsInfo(data: any) {
  return requestClient.post<any>('merchant/addOrEditSendGoodsInfo', data);
}

/**
 * 获取1688商品列表
 */
export async function get1688ShopList(data: any) {
  return requestClient.get<any>('yx1688/getProductList', {
    params: data,
  });
}

/**
 * 授权1688
 */
export async function auth1688(params: any) {
  return requestClient.get<any>('token/getAccessToken', {
    params,
  });
}

/**
 * 铺货授权
 */
export async function authDLY(params: any) {
  return requestClient.get<any>('token/getDLYAuth', {
    params,
  });
}

/**
 * 下单授权
 */
export async function authYPY(params: any) {
  return requestClient.get<any>('token/getYPYAuth', {
    params,
  });
}

/**
 * 上传图片
 */
export async function uploadImg(data: any) {
  return requestClient.post<any>('file/uploadFile', data, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}
/**
 * 获取上架的状态列表
 *
 */
export async function get1688ShopStatusList() {
  return requestClient.get<any>('business/getGoodsStatusList');
}

/**
 * 获取订单状态列表
 *
 */
export async function getOrderStatusList() {
  return requestClient.get<any>('order/getOrderStatusList');
}

/**
 * 店铺id登陆
 */
export async function loginShop(data: any) {
  const userStore = useUserStore();
  const { userInfo } = userStore;
  return requestClient
    .post<any>('api/registerByShopName', data)
    .then((res) => {
      const userData: any = userInfo || {};
      userData.userId = res.user_id;
      userStore.setUserInfo(userData);
      return res;
    })
    .catch((error) => {
      return error;
    });
}

/**
 * 图片搜索商品
 */
export async function searchImg(params: any) {
  return requestClient.get<any>('yx1688/getProductByImgUrl', { params });
}

/**
 * 发布预检查
 */
export async function publishCheck(params: any) {
  return requestClient.get<any>('doudian/publishPreCheck', { params });
}
